package com.superman.daoImpl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.superman.dao.UserDao;
import com.superman.domain.PageBean;
import com.superman.domain.Product;
import com.superman.domain.User;
import com.superman.utils.JDBCUtils;

public class UserDaoImpl implements UserDao {
	private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
	@Override
	public User login(User user) {
		String sql = "select * from user where email=? and password=?";
		try {
			return qr.query(sql, new BeanHandler<User>(User.class), user.getEmail(),user.getPassword());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("用户登录失败");
		}
	}
	@Override
	public int register(User user) {
		String sql ="insert into user  (email,password,nickname) values (?,?,?)";
		 try {
			return qr.update(sql, user.getEmail(),user.getPassword(),user.getNickname());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("");
		}
		
	}
	@Override
	public PageBean findAll() {
		String sql = "select * from product ";
		return null;
	}

}
